/**
 * @Title: SplashActivity.java
 * @Package com.unicom.eoms.activity
 * @Description: TODO  启动页
 * @author li_xiaoyue
 * @version 2013-4-2
 */
package com.hktf.moedokilock.activity;

import android.content.Intent;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hktf.corelib.eventBus.LoginEvent;
import com.hktf.corelib.jsonbean.UserDto;
import com.hktf.corelib.jsonbean.response.LoginResult;
import com.hktf.corelib.utils.CommUtils;
import com.hktf.corelib.utils.Config;
import com.hktf.corelib.utils.LogMds;
import com.hktf.moedokilock.R;
import com.hktf.uilib.app.BaseActivity;
import com.hktf.uilib.callback.BaseCallBackNew;
import com.hktf.uilib.engine.DriverEngine;
import com.hktf.uilib.utils.DlgUtils;
import com.lzy.okgo.model.Response;

import org.apache.commons.lang3.StringUtils;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * @author cdz
 * @ClassName: LoginActivity
 * @Description: TODO 登录页
 * @date 2025-3-2 上午9:15:07
 */
public class UserInfoActivity extends BaseActivity {


    private ImageView titlebarBack;
    private TextView titleText;
    private TextView tvRight1;
    private TextView tvRight;
    private RelativeLayout rlNickname;
    private TextView tvNickname;
    private RelativeLayout rlId;
    private TextView tvUserid;
    private RelativeLayout rlLogoff;
    private LinearLayout llLogin;
    private TextView tvExpirationTime;
    private TextView tvRemainTimes;


    @Override
    public boolean isLayoutFitsSystemWindows() {
        return false;
    }

    @Override
    public int getLayoutResID() {
        return R.layout.act_userinfo;
    }


    @Override
    public void initListener() {

    }






    @Override
    protected void onResume() {
        super.onResume();

    }

    @Override
    protected void onPause() {
        super.onPause();

    }

    protected void onDestroy() {
        super.onDestroy();

    }

    @Override
    public void initView() {
        setTitle(getString(com.hktf.uilib.R.string.userInfo));
        setBackClick();
        titlebarBack = findViewById(R.id.titlebar_back);
        titleText = findViewById(R.id.title_text);
        tvRight1 = findViewById(R.id.tv_right1);
        tvRight = findViewById(R.id.tv_right);
        rlNickname = findViewById(R.id.rl_nickname);
        tvNickname = findViewById(R.id.tv_nickname);
        rlId = findViewById(R.id.rl_id);
        tvUserid = findViewById(R.id.tv_userid);
        rlLogoff = findViewById(R.id.rl_logoff);
        llLogin = findViewById(R.id.ll_login);

        rlNickname.setOnClickListener(v -> {

//            startActivity(new Intent(UserInfoActivity.this, ModifyNicknameActivity.class));
        });
        rlLogoff.setOnClickListener(v -> {
            startActivity(new Intent(UserInfoActivity.this, LogOffActivity.class));
        });

        rlId.setOnClickListener(v -> {
            CommUtils.copy(Config.USERINFO.getUserId(), UserInfoActivity.this);
        });

        llLogin.setOnClickListener(v -> {
            startActivity(new Intent(UserInfoActivity.this, LoginActivity.class));
        });


        tvExpirationTime = findViewById(R.id.tv_expiration_time);
        tvRemainTimes = findViewById(R.id.tv_remain_times);
    }

    @Override
    public void initData() {
        UserDto userinfo = Config.USERINFO;
        if (userinfo == null) {
            return;
        }

        showLoadingGet();
        DriverEngine.userRefresh(new BaseCallBackNew<LoginResult>(LoginResult.class){
            @Override
            public void onSUCCESS(Response<LoginResult> response) {
                DlgUtils.disMissDlg();
                LoginResult loginResult = response.body();
                if (loginResult != null) {
                    UserDto userinfo = loginResult.getData();
                    if (userinfo != null) {
                        CommUtils.saveUserInfo(userinfo);
                        fillData();
                    }
                }
            }
        });
    }
    private void fillData(){
        UserDto userinfo = Config.USERINFO;
        if (userinfo != null) {
            tvNickname.setText(userinfo.getNickName());
            tvUserid.setText(userinfo.getUserId()+getString(com.hktf.uilib.R.string.copy_userid));
            String vipExpireTime1 = userinfo.getVipExpireTime1();
            if(StringUtils.isEmpty(vipExpireTime1)){
                vipExpireTime1=getString(com.hktf.uilib.R.string.vip_not);
            }
            CommUtils.setText(tvExpirationTime, vipExpireTime1);
            CommUtils.setText(tvRemainTimes,userinfo.getRemainTimes()+"");
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEvent(LoginEvent event) {
        LogMds.w("cdz", "收到消息了............login=");
        if (event != null) {
            int event_id = event.getEvent_id();
            switch (event_id) {
                case LoginEvent.CHANGE_USERINFO:
                    fillData();
                    break;
                case LoginEvent.GET_CODE_SUCCESS:

                    break;
            }
        }
    }

}
